package com.qhs.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.qhs.framework.base.BaseMapper;
import com.qhs.framework.base.BaseServiceImpl;
import com.qhs.framework.bean.DataTableView;
import com.qhs.framework.bean.PageView;
import com.qhs.framework.utils.BeanUtil;
import com.qhs.framework.utils.DateUtil;
import com.qhs.framework.utils.IDWorker;
import com.qhs.sys.mapper.SysUserInfoMapper;
import com.qhs.sys.entity.SysUserInfo;
import com.qhs.sys.service.UserService;
import org.apache.shiro.crypto.hash.Sha512Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * Created by xinchao on 2016/11/30 0030.
 */
@Service
public class UserServiceImpl extends BaseServiceImpl<SysUserInfo> implements UserService {

    @Autowired
    private SysUserInfoMapper sysUserInfoMapper;
    @Autowired
    private IDWorker idWorker;

    @Override
    public BaseMapper getMapper() {
        return sysUserInfoMapper;
    }

    @Override
    public SysUserInfo findUserByName(String username) {
        return sysUserInfoMapper.selectByName(username);
    }

    @Override
    public List<SysUserInfo> findUserByWhere(SysUserInfo userInfo) {
        return sysUserInfoMapper.findUserByWhere(userInfo);
    }

    @Override
    public DataTableView<SysUserInfo> findUserPageList(SysUserInfo userInfo, PageView pageView) {
        PageHelper.offsetPage(pageView.getStart(),pageView.getLength());
        return BeanUtil.toPagedResult(sysUserInfoMapper.findUserByWhere(userInfo),pageView);
    }

/*
    @Override
    public int insertUserInfo(SysUserInfo sysUserInfo){

        sysUserInfo.setId(idWorker.generateId());
        sysUserInfo.setSalt(UUID.randomUUID().toString().replace("-",""));
        sysUserInfo.setPassword(new Sha512Hash(sysUserInfo.getPassword(),sysUserInfo.getSalt()).toHex());
        sysUserInfo.setCreateTime(DateUtil.getDefaultDate());

        return sysUserInfoMapper.insertSelective(sysUserInfo);
    }

    @Override
    public int deleteByPrimaryKey(Long userId) {
        return sysUserInfoMapper.deleteByPrimaryKey(userId);
    }

    @Override
    public SysUserInfo selectByPrimaryKey(Long userId) {
        return sysUserInfoMapper.selectByPrimaryKey(userId);
    }

    @Override
    public int updateUser(SysUserInfo record) {
        return sysUserInfoMapper.updateByPrimaryKeySelective(record);
    }*/


}
